package com.example;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>按键事件管理器</p>
 *
 * @author dc
 * @date 2025-09-16
 **/
public class KeyEventBroadCast {
    private static KeyEventBroadCast instance;
    private final List<KeyEventListener> listeners = new ArrayList<>();

    public static KeyEventBroadCast getInstance() {
        if (instance == null) {
            instance = new KeyEventBroadCast();
        }
        return instance;
    }

    public void addListener(KeyEventListener listener) {
        listeners.add(listener);
    }

    public void removeListener(KeyEventListener listener) {
        listeners.remove(listener);
    }

    public void triggerScreenShot() {
        for (KeyEventListener listener : listeners) {
            listener.onScreenShotRequested();
        }
    }
    public void closeScreenShot() {
        for (KeyEventListener listener : listeners) {
            listener.closeScreenShot();
        }
    }

    public interface KeyEventListener {
        /**
         * 截屏请求
         */
        default void onScreenShotRequested(){}

        /**
         * 关闭当前窗口
         */
        default void closeScreenShot(){}
    }
}
